import 'package:flutter/material.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/constant/app_strings.dart';
import 'package:mall/ui/page/goods/order/order_list_page.dart';
import 'package:mall/ui/widgets/default_bg.dart';
import 'package:mall/utils/tabbar/app_tabbar.dart';

class OrderPage extends StatefulWidget {
  final int initIndex;

  OrderPage(this.initIndex);

  @override
  _OrderPageState createState() => _OrderPageState();
}

class _OrderPageState extends State<OrderPage> with SingleTickerProviderStateMixin {
  List<String> title = [
    AppStrings.ORDER_ALL,
    AppStrings.TO_BE_PAID,
    AppStrings.TO_BE_DELIVERED,
    AppStrings.TO_BE_RECEIVED,
    AppStrings.TO_BE_EVALUATED,
  ];

  late final TabController tabController =
      TabController(initialIndex: widget.initIndex, length: title.length, vsync: this);
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return APPScaffold(
      title: '我的订单',
      body: DefaultTabController(
        initialIndex: widget.initIndex,
        length: title.length,
        child: Container(
          padding: EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
          child: Column(
            children: [
              Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  color: Colors.white,
                ),
                height: 45,
                child: AppTabBar(
                  tabs: titleBars(),
                  tabAlignment: TabAlignment.fill,
                  // padding: const EdgeInsets.only(bottom: 15, top: 15, left: 8),
                  labelPadding: const EdgeInsets.only(right: 22),
                  controller: tabController,
                  indicatorColor: AppColors.C_FD2C55,
                  indicatorPadding: const EdgeInsets.only(bottom: 8),
                  isScrollable: false,
                  labelColor: AppColors.C_222222,
                  overlayColor: WidgetStateProperty.all(Colors.transparent),
                  unselectedLabelColor: AppColors.C_666666,
                  labelStyle: TextStyle(fontSize: 13, fontWeight: FontWeight.bold),
                  unselectedLabelStyle: TextStyle(fontSize: 13),
                ),
              ),
              SizedBox(height: 10),
              Expanded(
                child: TabBarView(
                  children: tabBarViews(),
                  controller: tabController,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> titleBars() {
    List<Widget> titles = [];
    title.forEach((element) {
      titles.add(Tab(text: element));
    });
    return titles;
  }

  List<Widget> tabBarViews() {
    List<Widget> tabBarViews = [];
    for (int i = 0; i < 5; i++) {
      tabBarViews.add(OrderListPage(showType: i));
    }
    return tabBarViews;
  }
}
